import 'package:another_flutter_splash_screen/another_flutter_splash_screen.dart';
import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hockey/extensions/jzx_widget_extension.dart';
import 'package:hockey/jzx_apps.dart';
import 'package:hockey/jzx_tabbar.dart';
import 'package:hockey/pages/jzx_intr_silder/jzx_intr_silder.dart';
import 'package:hockey/pages/jzx_login/jzx_login.dart';
import 'package:hockey/services/jzx_user.dart';

import 'controller.dart';

class JzxSplashView extends GetView<JzxSplashController> {
  const JzxSplashView({super.key});

  @override
  Widget build(BuildContext context) {
    return FlutterSplashScreen.fadeIn(
      backgroundColor: Colors.black,
      animationDuration: const Duration(milliseconds: 1000),
      onInit: () {
        debugPrint("On Init");
        JzxLogPvManger.tracking(page: JzxLogPages.launch);
      },
      onEnd: () {
        debugPrint("On End");
      },
      onAnimationEnd: () async {
        GetStorage box = GetStorage();
        final state = box.read(kFirstLaunch);
        if (state == null) {
          // if (!kDebugMode) {
          box.write(kFirstLaunch, true);
          // }
          Get.offAllNamed(kRouteJzxIntrSilder);
        } else {
          // login or tabbar
          if (await JzxUserService.to.isNeedLogin()) {
            Get.offAllNamed(kRouteJzxLogin);
          } else {
            Get.offAllNamed(kRouteTabbar);
          }
        }
      },
      childWidget: [
        Positioned(
          left: 0,
          right: 0,
          top: 186.w,
          child: Column(
            children: [
              Assets.logo.appLogo.image(
                width: 108.r,
                height: 108.r,
              ),
              JzxGaps.h24,
              Text(
                'StickFlow'.toUpperCase(),
                style: GoogleFonts.racingSansOne(
                  fontSize: 20.sp,
                  color: Colors.white,
                ),
              ),
            ],
          ),
        ),
      ].backgroud([
        Assets.images.launchBgv,
        // Assets.images.normalBgv,
      ]),
    );
  }
}
